﻿using Furion.DependencyInjection;
using Furion.FriendlyException;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;

namespace UpperComputer.Web.Core
{
    public class LogExceptionHandler : IGlobalExceptionHandler, IScoped
    {
        private readonly ILogger<LogExceptionHandler> _logger;
        public LogExceptionHandler(ILogger<LogExceptionHandler> logger)
        {
            _logger = logger;
        }
        public Task OnExceptionAsync(ExceptionContext context)
        {
            Exception exception = context.Exception;
            if (exception is not AppFriendlyException)
            {
                _logger.LogError(exception.Message, exception.StackTrace);
                //TODO:实现写入日志服务(从配置文件里读取日志服务相关)
            }
            return Task.CompletedTask;
        }
    }
}
